function e(e, t, a) {
    return t in e ? Object.defineProperty(e, t, {
        value: a,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = a, e;
}

var t = getApp(), a = require("../../utils/api.js");

Page({
    data: {
        info: [],
        showLoding: !1
    },
    onLoad: function(e) {
        var n = this, o = t.globalData.openid;
        a.getAllTicket({
            openid: o
        }).then(function(e) {
            if (console.log(e.data), 0 == e.errno) {
                var t = e.data.normal;
                0 == e.data.normal.length && n.setData({
                    showNo: !0
                });
                for (var a = 0; a < e.data.normal.length; a++) t[a].is_get = 0;
                n.autosize(t), n.getrange(t), n.setData({
                    info: t
                });
            } else n.setData({
                showNo: !0
            });
            n.setData({
                showLoding: !0
            });
        });
    },
    autosize: function(e) {
        for (var t = this, a = [], n = 0; n < e.length; n++) {
            var o = e[n].cut_price;
            o.split("").length <= 5 && (a[n] = 66), 6 == o.split("").length && (a[n] = 56), 
            7 == o.split("").length && (a[n] = 46), o.split("").length > 7 && (a[n] = 36);
        }
        t.setData({
            autoSize: a
        });
    },
    getrange: function(e) {
        var t = this, a = [];
        console.log(e);
        for (var n = 0; n < e.length; n++) {
            var o = e[n].range;
            if (console.log(o), o.length <= 0 && (a[n] = "全场所有商品可用"), o.length > 0) {
                for (var i = "", l = 0; l < o.length; l++) l == o.length - 1 ? i += o[l].gc_name ? o[l].gc_name : o[l].g_name : i += o[l].gc_name ? o[l].gc_name + "、" : o[l].g_name + "、";
                a[n] = i;
            }
            console.log(a[n]);
        }
        t.setData({
            getranges: a
        }), console.log(t.data.getranges);
    },
    tel: function(n) {
        var o = this, i = n.currentTarget.dataset.id, l = o.data.info;
        if ("" == i || void 0 == i) return wx.showToast({
            title: "非法进入",
            icon: "none",
            duration: 2e3
        }), !1;
        a.userGetTicket({
            openid: t.globalData.openid,
            tid: i
        }).then(function(t) {
            if (console.log(t), 0 == t.errno) {
                wx.showToast({
                    title: "领取成功，快去使用吧",
                    icon: "none",
                    duration: 2e3
                }), console.log(l);
                for (var a = 0; a < l.length; a++) if (i == l[a].id) {
                    console.log(l[a], i);
                    var n = "info[" + a + "].is_get";
                    o.setData(e({}, n, 1));
                }
            } else wx.showToast({
                title: t.message,
                icon: "none",
                duration: 2e3
            });
        });
    },
    todetail: function(e) {
        console.log(e);
        var t = e.currentTarget.dataset.id, a = e.currentTarget.dataset.type;
        wx.navigateTo({
            url: "/pages/personal/couponDetail?id=" + t + "&type=" + a
        });
    },
    touse: function() {
        wx.navigateTo({
            url: "/pages/template/index"
        });
    }
});